import PageBase from "../frameSccript/other/page/pageBase";
import { mgrs, sers } from "../frameSccript/system/OverallSystem ";
import ScrollViewExample from "./ScrollViewExample";

const { ccclass, property } = cc._decorator;

@ccclass
export default class rankingList extends PageBase {


    @property({ type: cc.Node, displayName: "滑动视图节点" })
    scrollView: cc.Node = null;
    @property({ type: cc.Node, displayName: "UI节点" })
    UINode: cc.Node = null;

    initSelectMode: number = 1;

    curSelectNode: cc.Node = null;


    @property(cc.Label)
    wodediqu:cc.Label = null

    start() {
        super.start();
        this.curSelectNode = this.UINode.children[0];

        this.wodepaiming()
    }


    /** 选择当前排行榜的模式 */
    selectCurMode(e, custom: string) {
        mgrs().soundMgr.playBtnSound();
        let tag = Number(custom);
        this.initSelectMode = tag;
        if (this.curSelectNode != null) {
            this.renewTargetSelectState(this.curSelectNode, false);
        }

        this.curSelectNode = e.currentTarget;
        this.renewTargetSelectState(e.currentTarget, true);
        let scroll = this.scrollView.getComponent(ScrollViewExample);
        scroll.renewShow();
    }

    /**
     * 更新目标选中状态
     * @param targetNode 目标
     * @param isShow 是否选中
     */
    renewTargetSelectState(targetNode: cc.Node, isSelect: boolean) {
        let select = targetNode.getChildByName("select");
        if (select != null) {
            select.active = isSelect;
        }
    }

    wodepaiming(){
        let diquData = sers().userSrv.getUserData().city
        if (diquData == null || diquData == '') {
            this.wodediqu.string = `未选地区`;
            return;
        }
        let duanwei = ''
        let UserData = sers().userSrv.getUserData()
        if(UserData.maxLevel>=8){
            duanwei = '·大师'
        }
        if(UserData.maxLevel >=11){
            duanwei = '·雀神'
        }
        
        this.wodediqu.string = `${diquData.cityName+duanwei} 地区排名:第${diquData.rank}名`;
    }
}
